import { defineConfig } from "vite";
import { VitePWA } from "vite-plugin-pwa";
import legacy from "@vitejs/plugin-legacy";

export default defineConfig({
  plugins: [
    legacy({
      targets: ["defaults", "not IE 11"],
    }),
    VitePWA({
      registerType: "autoUpdate",
      manifest: {
        name: "Phaser Game",
        short_name: "Game",
        theme_color: "#242424",
        icons: [
          {
            src: "/public/textures/icon.png",
            sizes: "192x192",
            type: "image/png",
          },
        ],
      },
      includeAssets: ["**/*.png", "**/*.ogg"],
    }),
  ],
  build: {
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes("phaser")) return "phaser";
          if (id.includes("node_modules")) return "vendor";
        },
      },
    },
  },
  resolve: {
    alias: {
      "@": "/src",
      "@assets": "/public/assets",
    },
  },
});
